package com.sangmo.fts.process.factoring.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;

@Entity
@Table(name = "ff_transfer_apply")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class FfTransferApply extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50)
    private String code;

    @One(value = "factoringContract", target = FfFactoringContract.class, fieldset = {"id", "code"},groups = {"FfTransferApply.search","FfTransferApply.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long contractId;

    @One(value = "applyCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long applyId;

    @One(value = "buyerCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long buyerId;

    @One(value = "bank", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long bankId;

    private BigDecimal totalAmount;

    private BigDecimal receivableAmount;

    private BigDecimal approvedAmount;

    @One(value = "applyConfirmDocument", target = FileUpload.class, fieldset = {"id","url","fileName"}, groups = {"FfTransferApply.detail"})
    @DataField(required = true)
    private Long applyConfirmDoc;

    @One(value = "invoiceConfirmDocument", target = FileUpload.class, fieldset = {"id","url","fileName"}, groups = {"FfTransferApply.detail"})
    @DataField(required = true)
    private Long invoiceConfirmDoc;

    @One(value = "transferNoticeDocument", target = FileUpload.class, fieldset = {"id","url","fileName"}, groups = {"FfTransferApply.detail"})
    @DataField(required = true)
    private Long transferNoticeDoc;

    @DataField(index = true)
    private boolean bankConfirm;

    private boolean buyerConfirm;

    private String state = States.PENDING;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Long getApplyId() {
        return applyId;
    }

    public void setApplyId(Long applyId) {
        this.applyId = applyId;
    }

    public Long getBuyerId() {
        return buyerId;
    }

    public void setBuyerId(Long buyerId) {
        this.buyerId = buyerId;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReceivableAmount() {
        return receivableAmount;
    }

    public void setReceivableAmount(BigDecimal receivableAmount) {
        this.receivableAmount = receivableAmount;
    }

    public BigDecimal getApprovedAmount() {
        return approvedAmount;
    }

    public void setApprovedAmount(BigDecimal approvedAmount) {
        this.approvedAmount = approvedAmount;
    }

    public Long getApplyConfirmDoc() {
        return applyConfirmDoc;
    }

    public void setApplyConfirmDoc(Long applyConfirmDoc) {
        this.applyConfirmDoc = applyConfirmDoc;
    }

    public Long getInvoiceConfirmDoc() {
        return invoiceConfirmDoc;
    }

    public void setInvoiceConfirmDoc(Long invoiceConfirmDoc) {
        this.invoiceConfirmDoc = invoiceConfirmDoc;
    }

    public Long getTransferNoticeDoc() {
        return transferNoticeDoc;
    }

    public void setTransferNoticeDoc(Long transferNoticeDoc) {
        this.transferNoticeDoc = transferNoticeDoc;
    }

    public boolean isBankConfirm() {
        return bankConfirm;
    }

    public void setBankConfirm(boolean bankConfirm) {
        this.bankConfirm = bankConfirm;
    }

    public boolean isBuyerConfirm() {
        return buyerConfirm;
    }

    public void setBuyerConfirm(boolean buyerConfirm) {
        this.buyerConfirm = buyerConfirm;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public interface States {
        String PENDING = "PENDING"; //待提交
        String SUBMITTED = "SUBMITTED"; //已提交
//        String REJECTED = "REJECTED"; //已驳回
    }

}
